package pwd.allen.mapper;

import pwd.allen.entity.Course;
import pwd.allen.entity.CourseDTO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

@Repository
public interface CourseMapper extends BaseMapper<Course> {

    /**
     * 关联出user集合
     * @param cid
     * @return
     */
    @Results(id = "my", value = {
            @Result(property = "users", column = "user_id", many = @Many(select = "com.atguigu.shardingjdbcdemo.mapper.UserMapper.selectByUserId", fetchType = FetchType.EAGER))
    })
    @Select("select * from myCourse where cid=#{cid}")
    CourseDTO mySelectById(Long cid);
}
